/******************************************************************************
COPYRIGHT 2012   : ATECH
Project          : 
Source File Name : Slave_lin1_dtype.h
Group            : SoftWare Team
Author           : 
Date First Issued: 12/18/2012                                                  
******************************************************************************/
#ifndef Slave_lin1_dtype_h 
#define Slave_lin1_dtype_h

/* #include */
#include "Slave_lin1_cfg.h"
/* replace yourself head files */
#include "derivative.h"
/* #define */
#define L_NULL  2
#define L_YES   1
#define L_OK    1
#define L_NO    0

#define L_TRUE   1
#define L_FALSE  0

#define L_SPECIAL  2
#define L_SUCCESS  1
#define L_FAILURE  0

#define L_ERROR_NO        0
#define L_ERROR_TIMEOUT   10
#define L_ERROR_CHECKSUM  11
#define L_ERROR_HEAD      12
#define L_ERROR_ID        13

#define L_ID_INDEX_NOTHING  0xff

#define CREAT_2_BYTESGROUP(data1,data0) ((l_u16)data1<<8)+((l_u16)data0)
#define CREAT_3_BYTESGROUP(data2,data1,data0) ((l_u32)data2<<16)+((l_u32)data1<<8)+((l_u32)data0)
#define CREAT_4_BYTESGROUP(data3,data2,data1,data0) ((l_u32)data3<<24)+((l_u32)data2<<16)+((l_u32)data1<<8)+((l_u32)data0)

#define BYTE_1st_OF_BYTESGROUP(data) ((l_u8)data)
#define BYTE_2nd_OF_BYTESGROUP(data) ((l_u8)(data>>8))
#define BYTE_3rd_OF_BYTESGROUP(data) ((l_u8)(data>>16))
#define BYTE_4th_OF_BYTESGROUP(data) ((l_u8)(data>>24))

#define CLR_COUNT(data) (data=0)
#define CLR_FLAG(data)  (data=0)
#define SET_FLAG(data)  (data=1)

#if(SLAVE_LIN1_CHANNEL == CHANNEL_SCI0)
    #define LIN1_Rx_ENABLE()        SCI0CR2_RIE=1 /* enable recevie interrupt */    
    #define LIN1_Rx_DISABLE()       SCI0CR2_RIE=0 /* disable recevier interrupt */     
      
    #define LIN1_UART_SEND_BUF      SCI0DRL
    #define LIN1_UART_RECEIVE_BUF   SCI0DRL
    #define LIN1_SEND_BREAK()       SCI0CR2_SBK=1;SCI0CR2_SBK=0 /* start sending one 13bit BREAK,fist high and then low */
#else
    #define LIN1_Rx_ENABLE()        SCI1CR2_RIE=1 /* enable recevie interrupt */    
    #define LIN1_Rx_DISABLE()       SCI1CR2_RIE=0 /* disable recevier interrupt */     
      
    #define LIN1_UART_SEND_BUF      SCI1DRL
    #define LIN1_UART_RECEIVE_BUF   SCI1DRL
    #define LIN1_SEND_BREAK()       SCI1CR2_SBK=1;SCI1CR2_SBK=0 /* start sending one 13bit BREAK,fist high and then low */
#endif

#define ID_TABLE_SIZE_DEFAULT  10
#define LIN1_ID_DIRECTION_RX   1 /* from the view of Slave to say */
#define LIN1_ID_DIRECTION_TX   0 /* It's different from Master */
#define LIN1_TIMEOUT_TIME      100 /* 100@10ms=1s<4s,Make sure node lost occurred before sleep */

//system macro
/* synch */
#define LIN_SYNCH           0x55

/*****************************************************************************/
/**
* Function Name: LIN1_UNCONDITIONAL_FRAME_CHECKSUM_TYPE
*                LIN1_DIAGNOSTIC_FRAME_CHECKSUM_TYPE
*                WAKEUP_FRAME_CHECKSUM_TYPE
*                LIN1_SLEEP_FRAME_CHECKSUM_TYPE
* Description:   config checksum type
*
* Param:   0: CLASSIC_CHECKSUM
*          1: ENHANCED_CHECKSUM 
*
*          ...
* Author:  
******************************************************************************/
#define CLASSIC_CHECKSUM        0
#define ENHANCED_CHECKSUM       1

#define LIN1_UNCONDITIONAL_FRAME_CHECKSUM_TYPE   ENHANCED_CHECKSUM
#define LIN1_DIAGNOSTIC_FRAME_CHECKSUM_TYPE      CLASSIC_CHECKSUM
#define LIN1_SLEEP_FRAME_CHECKSUM_TYPE           CLASSIC_CHECKSUM

/*****************************************************************************/
/**
* Function Name: 
* Description:   sleep
*
* Param:   
*          
*
*          ...
* Author:  
******************************************************************************/    
//sleep
#define SLEEP_ID            0x3C
#define SLEEP_FRAME_LENTH   8
#define LIN1_SLEEP_CHECKSUM_CLASSIC      0x00 /* classic checksum */
#define LIN1_SLEEP_CHECKSUM_ENHANCE      0xC3 /* enhance checksum */
#if(LIN1_SLEEP_FRAME_CHECKSUM_TYPE == CLASSIC_CHECKSUM)
    #define LIN1_SLEEP_CHECKSUM          LIN1_SLEEP_CHECKSUM_CLASSIC /* classic checksum */
#else
    #define LIN1_SLEEP_CHECKSUM          LIN1_SLEEP_CHECKSUM_ENHANCE /* enhanced checksum */
#endif
/// 0X00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
#define LIN1_SLEEP_FRAME_COMMAND  \
        0x00,0xFF,0xFF,0xFF, \
        0xFF,0xFF,0xFF,0xFF, \
        LIN1_SLEEP_CHECKSUM
        
/*****************************************************************************/
/**
* Function Name: 
* Description:   diagnosis
*
* Param:   
*          
*
*          ...
* Author:  
******************************************************************************/        
//diagnosis
#define DIAG_REQUEST_ID           0x3C
#define DIAG_RESPONSE_ID          0x7D
#define DIAG_PHYSIC_NAD           0x51
#define DIAG_FUNCTION_NAD         0x7E


#endif
